package cn.tedu.spring2205.week01.demo01;

import cn.tedu.spring2205.week01.demo01.config.MyConfig;
import cn.tedu.spring2205.week01.demo01.dao.PersonDao;
import cn.tedu.spring2205.week01.demo01.service.PersonService;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;

public class Week01Test {
    public static void main(String[] args) {
        //获取ApplicationContext对象
        ApplicationContext context = SpringApplication.run(MyConfig.class);
        //通过上下文对象获取某个Bean对象
//        UserDao dao = context.getBean(UserDao.class);
//        System.err.println(dao);

        //1. 根据类型获取StudentDao的Bean对象
//        StudentDao dao = context.getBean(StudentDao.class);
//        System.out.println(dao);

        //2. 根据beanId获取Bean对象
//        StudentDao studentDao = (StudentDao) context.getBean("studentDao");
//        System.out.println(studentDao);

        //3. 根据Beanid获取Bean对象，并指定数据类型
//        UserDao userDao = context.getBean("userDao",UserDao.class);
        //....

//        UserDao userDao1 = context.getBean("userDao",UserDao.class);
//        System.out.println(userDao==userDao1);

        //测试参数注入是否成功
        PersonDao personDao = context.getBean(PersonDao.class);

        PersonService personService = context.getBean(PersonService.class);
        PersonDao personDao1 = personService.getPersonDao();
        System.err.println(personDao1==personDao);

    }
}
